package com.zh.webcommon.common.param.constraint;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.RUNTIME;


/**
 * 支持String类型或Int类型的值
 * 参数值为null或空字符串视为有效
 * 可以配合@NotNull去约束不为null
 * @author ZH
 */
@Documented
@Constraint(validatedBy = ValueOptionValidate.class)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RUNTIME)
@Repeatable(ValueOptions.List.class)
public  @interface ValueOptions {

    /**
     * 指定选项值范围
     * @return
     */
    String[] options() default {};

    /**
     * 引用的枚举类的values，作为选项值范围
     * 若配置了options值，则ref会被忽略
     * @return
     */
    Class<? extends Enum> optionsRef() default Enum.class;

    String message() default "没有与值匹配的选项";


    Class<?>[] groups() default { };

    Class<? extends Payload>[] payload() default {};

    @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    public @interface List {
        ValueOptions[] value();
    }
}

